package com.freecloud.javabasics.thread.simple;

import com.freecloud.common.LoggerUtil;

/**
 * 使当前线程从执行状态，变为可执行状态。
 *
 * @Author: maomao
 * @Date: 2021-03-30 10:09
 */
public class YieldTest extends Thread {

    public YieldTest(String name){
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i <= 50; i++) {
            LoggerUtil.printThread("" + i);

            if (i == 30) {
                LoggerUtil.printThread("让出执行！");
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) {

        YieldTest y1 = new YieldTest("y1");
        YieldTest y2 = new YieldTest("y2");

        y1.start();
        y2.start();
    }
}
